package com.shuoyue.ycgk.ui.mine.info;

import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.appcatch.SPUtils;
import com.shuoyue.ycgk.base.BaseMvpActivity;
import com.shuoyue.ycgk.entity.Rule;
import com.shuoyue.ycgk.entity.UserInfo;
import com.shuoyue.ycgk.ui.common.RuleContract;
import com.shuoyue.ycgk.utils.MyRichTextHelper;
import com.shuoyue.ycgk.utils.ShareUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ShareGiftActivity2 extends BaseMvpActivity<RuleContract.Presenter>
        implements RuleContract.View, ShareContract.View {


    @BindView(R.id.back)
    ImageButton back;
    @BindView(R.id.page_title)
    TextView pageTitle;
    @BindView(R.id.iv_right)
    ImageView ivRight;
    @BindView(R.id.content)
    TextView content;
    @BindView(R.id.num)
    TextView num;
    ShareContract.Presenter sharePresenter;


    /**
     * 初始化layouy
     */
    @Override
    protected int getLayoutId() {
        return R.layout.activity_sharegift2;
    }

    /**
     * 初始化布局
     */
    @Override
    protected void initView() {
        pageTitle.setText("分享有礼");
        ivRight.setVisibility(View.VISIBLE);
        ivRight.setImageResource(R.mipmap.share);
    }


    @OnClick({R.id.back, R.id.iv_right, R.id.share})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.iv_right:
            case R.id.share:
                UserInfo user = SPUtils.getUserInfo(mContext);
                if (user != null) {
                    ShareUtil.shareUrl(this, ShareUtil.GIFT_URL + user.getId(),
                            "分享有礼",
                            "",
                            null);

                }

                break;
        }
    }

    @Override
    public void initData() {
        super.initData();
        mPresenter = new RuleContract.Presenter();
        mPresenter.attachView(this);
        sharePresenter = new ShareContract.Presenter();
        sharePresenter.attachView(this);

        mPresenter.getRule(1);
        sharePresenter.getInviteNum();
    }

    @Override
    public void setRule(Rule userInfo) {
//        GlideUtil.loadImage(mContext, userInfo.getImage(),R.mipmap.share_bg, img);
        MyRichTextHelper.showRich(mContext, userInfo.getContent(), content, false);
    }

    @Override
    public void setInviteNum(int a) {
        num.setText(Html.fromHtml("已邀请<font color='#2196F3'>" + a + "</font>人"));
    }

}
